<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ONLYOFFICE</title>
        <link rel="icon" href="favicon.ico" type="image/x-icon" />
       <style>
            html {
                height: 100%;
                width: 100%;
            }

            body {
                background: #fff;
                color: #333;
                font-family: Arial, Tahoma,sans-serif;
                font-size: 12px;
                font-weight: normal;
                height: 100%;
                margin: 0;
                overflow-y: hidden;
                padding: 0;
                text-decoration: none; 
            }

            .form {
                height: 100%;
            }

            div {
                margin: 0;
                padding: 0;
            }
       </style>
 
       
        <!-- <script type="text/javascript" src="http://101.201.235.48:8000/web-apps/apps/api/documents/api.js"></script> -->
        <script type="text/javascript" src="http://192.168.1.207:99/web-apps/apps/api/documents/api.js"></script>


        <script type="text/javascript">
        var doca;

        var innerAlert = function (message) {
            if (console && console.log)
                console.log(message);
        };

        var onReady = function () {
            innerAlert("Document editor ready");
        };
        var getUrlParams = function (name) {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)")
            var r = window.location.search.substr(1).match(reg)
            if (r!=null) return decodeURIComponent(r[2])
            return null
        }
        var fileUrl = getUrlParams('fileUrl')
        var doctype = ''
        var doc1 = [".doc", ".docm", ".docx", ".dot", ".dotm", ".dotx", ".epub", ".fodt", ".htm", ".html", ".mht",".odt", ".ott", ".pdf", ".rtf",".txt", ".djvu", ".xps"]
        var doc2 = [".csv", ".fods", ".ods", ".ots", ".xls", ".xlsm", ".xlsx", ".xlt", ".xltm", ".xltx"]
        var doc3 = [".fodp", ".odp", ".otp", ".pot", ".potm", ".potx", ".pps", ".ppsm", ".ppsx", ".ppt", ".pptm", ".pptx"]
        if (doc1.includes(fileUrl.substring(fileUrl.lastIndexOf('.')))) {
            doctype = "text"
        } else if (doc2.includes(fileUrl.substring(fileUrl.lastIndexOf('.')))) {
            doctype = "spreadsheet"
        } else if (doc3.includes(fileUrl.substring(fileUrl.lastIndexOf('.')))) {
            doctype = "presentation"
        }
        var onDocumentStateChange = function (event) {
            var title = document.title.replace(/\*$/g, "");
            document.title = title + (event.data ? "*" : "");
        };

        var onRequestEditRights = function () {
            location.href = location.href.replace(RegExp("mode=view\&?", "i"), "");
        };

        var onError = function (event) {
            if (event)
                innerAlert(event.data);
        };
        function randomString(len, charSet) {
            charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
            var randomString = '';
            for (var i = 0; i < len; i++) {
                var randomPoz = Math.floor(Math.random() * charSet.length);
                randomString += charSet.substring(randomPoz,randomPoz+1);
            }
            return randomString;
        }
        var onOutdatedVersion = function (event) {
            location.reload(true);
        };
        console.log(fileUrl)
        var сonnectEditor = function () {
        var config = {
                type: "desktop",
                height: "100%",
                width: "100%",
                documentType: doctype,
                document:{
                    fileType: fileUrl.substring(fileUrl.lastIndexOf('.') + 1),
                    key: randomString(15),
                    title: fileUrl.substring(fileUrl.lastIndexOf('.'), fileUrl.lastIndexOf('/') + 1),
                    url: fileUrl
                },
                editorConfig: {
                    mode: 'view',
                    // callbackUrl: "http://101.201.235.48:8000/CallBackServlet?fileName=" + fileUrl,
                    callbackUrl: "http://192.168.33.200:8019/Office.ashx?fileNmes=" + fileUrl,
                    customization: {
                        forcesave: "true"
                    },
                    user: {
                        id: "78ele84121",
                        name: "John Smith"
                    },
                    lang: "zh-CN",
                },

           };
            // console.log("editor : сonnectEditor config = " + config);
            // console.log(config);

            docEditor = new DocsAPI.DocEditor("iframeEditor", config);
        };
        if (window.addEventListener) {
            window.addEventListener("load", сonnectEditor);
        } else if (window.attachEvent) {
            window.attachEvent("load", сonnectEditor);
        }

    </script>

    </head>
    <body>
        <div class="form">
            <div id="iframeEditor"></div>
        </div>
    </body>
</html>